﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PoshBoard.VisualDesigner.Controls
{
    public class NewGrid : Grid,IPBComponentBase
    {
        public string CommandBase { get { return  "New-Grid"; }}

        public string PSName { get; set; }

        public void BuildPSName(string parentName)
        {
            this.PSName = "$" + this.Name;
        }

        public string GetConstructionScript()
        {
            return PSScriptHelper.BuildPSScript(this, this.Name, this.Children.Cast<IPBComponentBase>().ToList());
        }

        public string GetParameters()
        {
            //string param = PSScriptManager.GetCommonParameters(this);
            string param = string.Empty;

            if (this.RowDefinitions.Count > 0)
            {
                string rowValue = string.Empty;
                foreach (RowDefinition row in this.RowDefinitions)
                {
                    rowValue += "'" + row.ActualHeight.ToString() + "'";
                }
                param += " -Rows" + rowValue;
            }

            if (this.ColumnDefinitions.Count > 0)
            {
                string colValue = string.Empty;
                foreach (ColumnDefinition col in this.ColumnDefinitions)
                {
                    if (colValue != string.Empty)
                        colValue += ",";

                    if(col.Width.IsStar)
                        colValue += "'" + col.Width.Value.ToString() + "*'";
                    else
                        colValue += "'" + col.Width.Value.ToString() + "'";
                }
                param += " -Columns " + colValue;
            }


            return param;
        }
    }
}
